<extend name='Public/index'/>
<block name='content'>
    <style>
    input[type=checkbox] {
        width: 30px;
        height: 55px;
    }
	</style>
    <table id="point_ruleTb1">
        <thead>
        <tr>
            <td>姓名</td>
            <volist name="rule" id="rule">
            <td id="<{$rule.point_rule_id}>"><{$rule.rule_name}></td>
            </volist>
            <th>操作</th>
        </tr>
        </thead>

        <tbody>
        <volist name="nav1" id="nav1">

            <tr id="row_<{$nav1.student_id}>">
                <td><input name="sname" class="es"style="width:6em;" readonly type="text" value=<{$nav1.sname}>></td>
                <volist name="nav1.roleall" id="rule">
                    <td><input class="rows_<{$nav1.student_id}>" type="checkbox" value="<{$rule.point_rule_id}>" disabled></td>

                </volist>
                <td>
                    <button onclick="edit('<{$nav1.student_id}>')" class="button tiny edit ">编辑</button>
                    <button onclick="save('<{$nav1.student_id}>')" style="display: none;" class="button tiny save">提交</button>
                </td>
            </tr>
        </volist>
        </tbody>
    </table>
    <script>
        $('tbody td').click(function(){
            var index = $(this).index();
            var point_rule_id=$('thead tr td').eq(index).prop('id');
            //console.log(point_rule_id);
        });

        $('input[type=checkbox]').click(function () {
            var id = $(this).parent().parent().prop('id');
            //console.log(id);
        })

     function edit(rowid) {
         $('.rows_'+rowid).prop('disabled',false);
         $('#row_'+rowid+' .edit').hide();
         $('#row_'+rowid+' .save').show();
     }
     function save(id) {
         //扣分项id值
        a=$('.rows_'+id+':checked').map(function(){return $(this).val();}).get().join(",");
//console.log(a);
         var index = $(this).index();
            //var point_rule_id=$('thead tr td').eq(index).prop('id');

         $('.rows_' + id).prop('disabled', true);
         $('#row_' + id + ' .edit').show();
         $('#row_' + id + ' .save').hide();
         var ctime=new Date().getTime();
         var data = {
             student_id:id,
             point_rule_id:a,
         }
         console.log(data);
         $.post('<{:U("deduct")}>', data, function (data) {
                console.log(data);
				alert('扣分成功');
				window.location.href='<{:U("readCredit")}>';
         })
     }
    </script>

</block>